package com.hgm.travelapp.fragment

import android.os.Bundle
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.fragment.app.DialogFragment
import com.hgm.travelapp.R

class NameDialog : DialogFragment() {

      override fun onCreateView(
            inflater: LayoutInflater,
            container: ViewGroup?,
            savedInstanceState: Bundle?
      ): View? {
            //绑定控件
            val view = inflater.inflate(R.layout.changename_dialog_fragment, container, false)
            val cancel = view.findViewById<Button>(R.id.btn_cancel)
            val sure = view.findViewById<Button>(R.id.btn_sure)
            //点击事件
            cancel.setOnClickListener {
                  dismiss()
            }
            sure.setOnClickListener {
                  dismiss()
                  //TODO 修改名称的业务逻辑

            }
            return view
      }

      override fun onStart() {
            super.onStart()
            if (dialog != null) {
                  val metrics = resources.displayMetrics
                  //宽度设为屏幕宽度的90%
                  dialog!!.window?.setLayout( (metrics.widthPixels * 0.9).toInt(), ViewGroup.LayoutParams.WRAP_CONTENT)
            }
      }

}